package cn.example.zjgsu.controller;

import cn.example.zjgsu.exception.MyException;
import cn.example.zjgsu.pojo.result.JsonData;
import cn.example.zjgsu.service.HomePageServer;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author xuejiahui
 * @date 2020/3/15 -20:37
 */

@RestController
@RequestMapping({"/v1/api/homepage"})
@Api(description = "首页接口")
public class HomePageController {

    @Autowired
    HomePageServer homePageServer;
    @ApiOperation("获取全国精选")
    @GetMapping(value = "/getNationalSelection")
    public JsonData getNationalSelection(){
        return JsonData.success(homePageServer.getNationalSelection());
    }

    @ApiOperation("根据城市名字获取城市id")
    @GetMapping(value = "/getCityId")
    public JsonData getCityIdByName(String cityname){
        return JsonData.success(homePageServer.getCityIdByName(cityname));
    }


    @ApiOperation("根据城市id获取城市信息")
    @GetMapping(value = "/getCityIntroductionById")
    public JsonData getCityIntroduction(int cityid){
        return JsonData.success(homePageServer.getCityInformation(cityid));
    }


    @ApiOperation("根据城市id获取城市特色菜")
    @GetMapping(value = "/getCityFood")
    public JsonData getFoodByCityId(int cityid){
        return JsonData.success(homePageServer.getFoodByCityId(cityid));
    }


    @ApiOperation("根据城市id获取城市特色餐馆")
    @GetMapping(value = "/getCityShop")
    public JsonData getShopByCityId(int cityid){
        return JsonData.success(homePageServer.getShopByCityId(cityid));
    }


    @ApiOperation("根据食物id获取特色餐馆")
    @GetMapping(value = "/getShopByFood")
    public JsonData getShopByFoodId(int foodid){
        return JsonData.success(homePageServer.getShopByFoodId(foodid));
    }


    @ApiOperation("根据店铺id获取城市特色菜")
    @GetMapping(value = "/getFoodByShop")
    public JsonData getFoodByShopId(int shopid){
        return JsonData.success(homePageServer.getFoodByShopId(shopid));
    }

    @ApiOperation("根据城市id获取城市特色食记")
    @GetMapping(value = "/getCityFoodRecord")
    public JsonData getFoodRecordByCityId(int cityid){
        return JsonData.success(homePageServer.getFoodRecordByCityID(cityid));
    }


    @ApiOperation("根据店铺id获取具体的店铺信息")
    @GetMapping(value = "/getshopbyshopid")
    public JsonData getShopByShopId(int shopid){
        return JsonData.success(homePageServer.getShopByShopId(shopid));
    }

    @ApiOperation("模糊查询全国美食")
    @GetMapping("/queryFood")
    public  JsonData fuzzyQueryFood(String foodname){
        try {
            return JsonData.success(homePageServer.fuzzyQueryFood(foodname));
        } catch (MyException e) {
            return JsonData.fail(e.getMessage());
        }
    }
}
